package com.culture.bootdemo.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.culture.bootdemo.model.vo.ReadData;
import com.culture.bootdemo.service.UploadService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author wen
 * @date 2019/11/15 18:30
 * @Description
 **/
@Service
@Slf4j
public class UploadServiceImpl implements UploadService {

    @Override
    public void saveData(List list) {
        log.info(JSON.toJSONString(list));

        //此处入库最好用 批量入库  而不是遍历写每条insert
        list.stream().forEach(l -> {
            JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(l));
            ReadData readData = JSONObject.toJavaObject(jsonObject, ReadData.class);
            System.out.println(readData.toString());
            System.out.println(readData.getDate());
        });
    }
}
